package com.solotiger.geographic.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.solotiger.geographic.biz.model.Album;
import com.solotiger.geographic.ui.view.AlbumHolderView;

import java.util.ArrayList;
import java.util.List;

/**AlbumAdapter
 * album的Adapter
 */
public class AlbumAdapter extends BaseAdapter {

    private List<Album> datas;

    private Context context;

    public AlbumAdapter(Context context) {
        datas = new ArrayList<>();
        this.context = context;
    }


    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Album getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        AlbumHolderView holder;
        if (convertView != null) {
            holder = (AlbumHolderView) convertView;
        } else {
            holder = new AlbumHolderView(context);
        }

        holder.setData(getItem(position));
        return holder;
    }

    /**
     * 加载更多
     *
     * @param datas
     */
    public void notifyDataSetChanged(List<Album> datas) {
        if (datas != null) {
            this.datas.addAll(datas);
            super.notifyDataSetChanged();
        }
    }

    /**
     * 清空数据
     */
    public void clearData() {
        if (datas != null) {
            datas.clear();

        }
    }
}
